home *** CD-ROM | disk | FTP | other *** search
/ CD Actual 1 / PC Actual CD 01.iso / f1 / cimb.arj / VMS.C < prev    next >
Encoding:
C/C++ Source or Header  |  1994-08-31  |  2.6 KB  |  110 lines

  1. /*==============================================================================
  2.  
  3. FICHERO: VMS.C
  4.  
  5. AUTOR: ANTONIO LADESA JURADO
  6.  
  7. FECHA: 24/6/94
  8.  
  9. DESCRIPCION:
  10.  
  11.     Fichero que contiene las estructuras, constantes, variables y funciones
  12.     internas y externas para la gestión de memoria VMS.
  13.  
  14. ==============================================================================*/
  15.  
  16.  
  17. /*---- MODULOS USADOS --------------------------------------------------------*/
  18.  
  19. #include <string.h>
  20. #include <stdio.h>
  21. #include <io.h>
  22. #include <dir.h>
  23. #include <dos.h>
  24. #include <alloc.h>
  25. #include "vms.h"
  26.  
  27. /*---- CODIFICACION DE LAS FUNCIONES OFRECIDAS -------------------------------*/
  28.  
  29.  
  30. /*---- FUNCION: extern VMSmemoria *VMSmemReservar(long int bytes) --------------
  31.  
  32.     Descripción:
  33.  
  34.         Esta función reserva un número de bytes de memoria VMS, es decir,
  35.         crea un fichero de ese tamaño.
  36.  
  37.     Parámetros:
  38.  
  39.         long int bytes: número de bytes a reservar.
  40.  
  41.     Retorno:
  42.  
  43.         - Puntero a estructura del gestor VMS, que contiene los datos del fichero
  44.         - Si hubo error, el puntero a fichero del gestor, es NULL.
  45.  
  46. ---- CODIGO: -----------------------------------------------------------------*/
  47.  
  48. extern VMSmemoria *VMSmemReservar(long int bytes)
  49. {
  50.     /* gestor de memoria VMS */
  51. VMSmemoria VMSmem;
  52.     /* manejador temporal */
  53. int manejador;
  54.  
  55.     /* inicializa gestor VMS */
  56. strcpy(VMSmem.fichero,"\\");
  57. VMSmem.gestor = NULL;
  58.     /* crea fichero */
  59. manejador = creattemp(VMSmem.fichero, FA_ARCH);
  60. if(manejador != -1)
  61.     close(manejador);
  62. else
  63.     return(&VMSmem);
  64.  
  65.     /* abrir fichero */
  66. if((VMSmem.gestor = fopen(VMSmem.fichero,"wb+"))==NULL)
  67.     return(&VMSmem);
  68.  
  69.     /* si no es lo suficientemente grande...*/
  70. fseek(VMSmem.gestor,0,SEEK_SET);
  71. while(bytes--)
  72.     {
  73.     if(fputc(0,VMSmem.gestor))
  74.         {
  75.         fclose(VMSmem.gestor);
  76.         return(&VMSmem);
  77.         }
  78.     }
  79.     /* devuelve gestor */
  80. return(&VMSmem);
  81. }
  82.  
  83. /*---- FIN FUNCION -----------------------------------------------------------*/
  84.  
  85.  
  86. /*---- FUNCION: extern void VMSmemLiberar(VMSmemoria VMSmem) -------------------
  87.  
  88.     Descripción:
  89.  
  90.         Esta función libera memoria VMS reservada anteriormente.
  91.         Es decir, borra el fichero.
  92.  
  93.     Parámetros:
  94.  
  95.         VMSmemoria VMSmem : gestor de memoria VMS a liberar
  96.  
  97. ---- CODIGO: -----------------------------------------------------------------*/
  98.  
  99. extern void VMSmemLiberar(VMSmemoria VMSmem)
  100. {
  101.     /* si el fichero está abierto, cerrarlo y borrarlo */
  102. if(VMSmem.gestor!=NULL)
  103.     {
  104.     fclose(VMSmem.gestor);
  105.     remove(VMSmem.fichero);
  106.     }
  107. }
  108.  
  109. /*---- FIN FUNCION -----------------------------------------------------------*/
  110.